package com.baosight.sczx.zm.cf.service;

import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.basetools.TablePk;
import com.baosight.sczx.common.zm.cInterface.Department;
import com.baosight.sczx.zm.cf.domain.ZMCFContactFeedback;
import com.baosight.sczx.zm.cf.domain.ZMCFContactReceive;

/**
 * 业务联系单
 * <p>Title: ServiceZMCF25.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 严洪浩
 * @version 1.0
 * <pre>Histroy:
 *          2011-7-6 上午07:44:02  严洪浩  Create
 *</pre>
 */
public class ServiceZMCF25 extends ServiceEPBase {

	/**
	 * 初始化方法
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCF25</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-7-8上午01:09:11 严洪浩
	 * </p>
	 *
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);
		outInfo.addBlock(Department.getInstance().getConstructionUnit(false));//部门
		return outInfo;
	}

	/**
	 * 查询
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCF25</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-7-8上午01:09:01 严洪浩
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) {
		if(inInfo.getBlock(EiConstant.queryBlock) == null){
			StaticTools.setQueryParameters(inInfo, "fdEndDate", StaticTools.getDate() + " 23:59:59", true);
		}
		else {
			String endTime = inInfo.getBlock(EiConstant.queryBlock).getCellStr(0, "fdEndDate");
			if(null != endTime && !"".equals(endTime)) {
				if(endTime.length() <= 10) {
					StaticTools.setQueryParameters(inInfo, "fdEndDate", endTime + " 23:59:59", true);
				}
			}
		}
		
		String fdReveiveId = UserSession.getInSessionProperty("orgCode") == null ? "" : UserSession.getInSessionProperty("orgCode").toString();//发送部门
		StaticTools.setQueryParameters(inInfo, "fdReveiveId", fdReveiveId, true);//添加查询条件
		StaticTools.setQueryParameters(inInfo, "fdStatus", "草拟", true);//添加查询条件
		EiInfo outInfo = super.query(inInfo, "ZMCFContactReceive.query", new ZMCFContactReceive());
		return outInfo;
	}
	
	/**
	 * 反馈
	 * <p>Function: feedback</p>
	 * <p>Description: </p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-7-8上午02:02:19 严洪浩
	 * </p>
	 *
	 */
	public EiInfo feedback(EiInfo inInfo) {
		String fdSendDepartId = UserSession.getInSessionProperty("orgCode") == null ? "" : UserSession.getInSessionProperty("orgCode").toString();//反馈部门
		String fdSendDepart = Department.getInstance().getDepartmentNameById(fdSendDepartId);
		String fdSendPersonId = UserSession.getUserId() == null ? "" : UserSession.getUserId().toString();//反馈人ID
		String fdSendPerson = (String) UserSession.getInSessionProperty("UserCname");//反馈人
		String fdSendTime = StaticTools.getDateTime();//反馈时间
		String fdContactListId = inInfo.getBlock("result").getCellStr(0, "fdContactlistId");
		
		EiInfo outInfo = super.update(inInfo, "ZMCFContactReceive.modifyFeedbackOk");//更新联系单状态
		
		inInfo.addBlock("resultDetails").addBlockMeta(new ZMCFContactFeedback().eiMetadata);
		
		inInfo.getBlock("resultDetails").setCell(0, "fdKeyId", TablePk.getInstance().getNextValue("T_CF_CONTACTLISTFEEDBACK"));
		inInfo.getBlock("resultDetails").setCell(0, "fdContactListId", fdContactListId);
		inInfo.getBlock("resultDetails").setCell(0, "fdSendDepartId", fdSendDepartId);
		inInfo.getBlock("resultDetails").setCell(0, "fdSendDepart", fdSendDepart);
		inInfo.getBlock("resultDetails").setCell(0, "fdSendPersonId", fdSendPersonId);
		inInfo.getBlock("resultDetails").setCell(0, "fdSendPerson", fdSendPerson);
		inInfo.getBlock("resultDetails").setCell(0, "fdContent", inInfo.getBlock("result").getCellStr(0, "fdFeedbackContent"));
		inInfo.getBlock("resultDetails").setCell(0, "fdSendTime", fdSendTime);
		inInfo.getBlock("resultDetails").setCell(0, "fdModifyFlag", "0");
		
		outInfo = super.insert(inInfo, "ZMCFContactFeedback.insert", "resultDetails");//主表状态
		return outInfo;
	}
}
